package com.youth.youthservice.controller;


import com.youth.commonutils.R;
import com.youth.servicebase.exceptionhandler.GlobalException;
import com.youth.youthservice.entity.EduChapter;
import com.youth.youthservice.entity.chapter.ChapterVo;
import com.youth.youthservice.service.EduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程章节 前端控制器
 * </p>
 *
 * @author CM
 * @since 2023-4-30
 */
@Api(description = "课程里面的章节")
@RestController
@RequestMapping("/eduservice/chapter")
//使用nginx是需要使用@CrossOrigin解决跨域问题的，现在使用gateway网关替代   /*解决跨域问题*/
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;

    @ApiOperation("查询某一课程的章节和小结（视频）")
    @GetMapping("getChapterVideo/{id}")
    public R getChapterByCourseId(@PathVariable("id") String courseId){
        List<ChapterVo> chapterVos = chapterService.getChapterByCourseId(courseId);
        return R.ok().data("list",chapterVos);
    }

    @ApiOperation("为课程添加章节")
    @PostMapping("/addChapter")
    public R addChapterForCourse(@RequestBody EduChapter chapter){
        return chapterService.addChapter(chapter);
    }

    @ApiOperation("修改章节信息时回显章节信息")
    @GetMapping("/getChapterInfo/{id}")
    public R getChapterInfo(@PathVariable("id") String id){
        return R.ok().data("eduChapter",chapterService.getById(id));
    }

    @ApiOperation("更新课程章节信息")
    @PostMapping("updateChapter")
    public R updateChapterById(@RequestBody EduChapter eduChapter){
        chapterService.updateById(eduChapter);
        return R.ok();
    }

    @ApiOperation("删除课程的对应章节")
    @DeleteMapping("{id}")
    public R deleteChapterById(@PathVariable("id") String chapterId){
        return chapterService.deleteById(chapterId);
    }


}












